
*******************************************************************************************
*******************************************************************************************
******************** Reclassification Risk in the Small Group Health Insurance Market
******************* by Sebastian Fleitas, Gautam Gowrisankaran and Anthony Lo Sasso 
*******************************************************************************************
*******************************************************************************************
*******************************************************************************************
******************** Table 3 MEPS
*******************************************************************************************
*******************************************************************************************
*******************************************************************************************
 

clear all

global dir_data "/Users/sebastianfleitas/Dropbox/MULTICHOICE_PROJECT/PREMIUMS_AND_HEALTHSHOCKS/Tables_RESTAT/Do_files_Analysis/MEPS/Data"
global dir_do   "/Users/sebastianfleitas/Dropbox/MULTICHOICE_PROJECT/PREMIUMS_AND_HEALTHSHOCKS/Tables_RESTAT/Do_files_Analysis/MEPS/DoFiles"

do "$dir_do/aux_2013_OutsideOption.do"
do "$dir_do/aux_2014_OutsideOption.do"

use "$dir_data/aux_2013_OutsideOption", clear 

merge 1:1 DUPERSID using "$dir_data/aux_2014_OutsideOption"

reshape long firmsize changejob changejobwhy jobinsurance jobinsurance_offered age, i(DUPERSID) j(round)  


*** Strategy: Conditional on insurance offered in job, estimate the probability of people
*** choosing insurance in the small group market.

keep if round==1

gen inside_option = (jobinsurance==1) 

egen numid=group(DUPERSID)
sort numid round
tsset numid round

*** rename conditions 
rename status_BloodPressure code_hypertension
rename status_heartdisease code_heartfailure
rename status_AMI code_ami
rename status_stroke code_brainhemorr
rename status_cancer code_cancer2
rename status_diabetes code_diabetes 
rename status_asthma code_asthma 
rename status_bronchitis code_respfailure

*** Get the industry number 
*gen ind_aux =  substr(sic_cd,1,4)
*destring ind_aux, replace
gen ind_aux = 1 if INDCAT31==1 
replace ind_aux =2 if INDCAT31==2
replace ind_aux =3 if INDCAT31==3
replace ind_aux =4 if INDCAT31==4
replace ind_aux =5 if INDCAT31==6
replace ind_aux =5 if INDCAT31==7
replace ind_aux =6 if INDCAT31==5
replace ind_aux =7 if INDCAT31==7
replace ind_aux =7 if INDCAT31==9
replace ind_aux =8 if INDCAT31==10
replace ind_aux =8 if INDCAT31==11
replace ind_aux =8 if INDCAT31==12
replace ind_aux =9 if INDCAT31==13
replace ind_aux =9 if INDCAT31==14 
replace ind_aux =9 if INDCAT31==15

tab ind_aux, gen(industry_dummy)

probit inside_option age SEX code_* industry_dummy* firmsize, noconstant
/*
local n_probit = e(N)
matrix V = e(V) * `n_probit'
*mat2txt, matrix(V) saving("~/Dropbox/MULTICHOICE_PROJECT/MEPS/DoFiles/table") 
drop _all
svmat double V
saveold "~/Dropbox/MULTICHOICE_PROJECT/MEPS/DoFiles/Vmeps", replace 
exit
*/ 
gen sample = e(sample)
margins, dydx(*)

sum inside_option age SEX code_* industry_dummy* firmsize if sample==1

*estpost tabstat inside_option age SEX firmsize code_hypertension code_heartfailure code_ami code_brainhemorr code_cancer2 code_diabetes code_asthma code_respfailure  if sample==1 , /* 
* */  statistics( mean sd) /* 
* */  columns(variables)
*esttab using myfile.tex,  /* 
* */ cells("inside_option age SEX firmsize code_hypertension code_heartfailure code_ami code_brainhemorr code_cancer2 code_diabetes code_asthma code_respfailure") /* 
* */  replace nonum noobs
 
 
 
 estpost tabstat inside_option age SEX firmsize if sample==1 , /* 
 */  statistics( mean sd) /* 
 */  columns(variables)
esttab using myfile.tex,  /* 
 */ cells("inside_option age SEX firmsize") /* 
 */  replace nonum noobs
